]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
keyboard: Allow for terminal variants in specific languages
authorCarlos Garnacho <carlosg@gnome.org>
Fri, 26 Jan 2024 16:42:52 +0000 (17:42 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Thu, 29 Feb 2024 15:34:21 +0000 (16:34 +0100)
Do not hardcode the us-terminal OSK keymap, and append '-extended'
to the current group name, accounting with the existing 'us' fallback.
This allows for concerned individuals to propose language-specific
terminal layouts.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3162>

js/ui/keyboard.js

index 7089609a01189ed301c3096915cc10316f59d172..05ea5bad655feb51252a11dc3553c233aa74a384 100644 (file)
@@ -496,18 +496,7 @@ const Key = GObject.registerClass({
 
 class KeyboardModel {
     constructor(groupName) {
-        let names = [groupName];
-        if (groupName.includes('+'))
-            names.push(groupName.replace(/\+.*/, ''));
-        names.push('us');
-
-        for (let i = 0; i < names.length; i++) {
-            try {
-                this._model = this._loadModel(names[i]);
-                break;
-            } catch (e) {
-            }
-        }
+        this._model = this._loadModel(groupName);
     }
 
     _loadModel(groupName) {
@@ -1460,15 +1449,36 @@ export const Keyboard = GObject.registerClass({
         }
     }
 
-    _updateLayoutForGroup(groupName) {
-        let keyboardModel = new KeyboardModel(groupName);
-        let levels = keyboardModel.getLevels();
+    _updateLayout(groupName, purpose) {
+        let keyboardModel = null;
         let layers = {};
         let layout = new Clutter.Actor({
             layout_manager: new Clutter.BinLayout(),
             x_expand: true,
             y_expand: true,
         });
+
+        let groups = [groupName];
+        if (groupName.includes('+'))
+            groups.push(groupName.replace(/\+.*/, ''));
+        groups.push('us');
+
+        if (purpose === Clutter.InputContentPurpose.TERMINAL)
+            groups = groups.map(g => `${g}-extended`);
+
+        for (const group of groups) {
+            try {
+                keyboardModel = new KeyboardModel(group);
+            } catch (e) {
+                // Ignore this error
+            }
+        }
+
+        if (!keyboardModel)
+            return;
+
+        let levels = keyboardModel.getLevels();
+
         for (let i = 0; i < levels.length; i++) {
             let currentLevel = levels[i];
             /* There are keyboard maps which consist of 3 levels (no uppercase,
@@ -1495,13 +1505,8 @@ export const Keyboard = GObject.registerClass({
     }
 
     _ensureKeys() {
-        let group;
-        if (this._purpose === Clutter.InputContentPurpose.TERMINAL)
-            group = 'us-extended';
-        else
-            group = this._keyboardController.getCurrentGroup();
-
-        this._updateLayoutForGroup(group);
+        const group = this._keyboardController.getCurrentGroup();
+        this._updateLayout(group, this._purpose);
     }
 
     _addRowKeys(keys, layout) {